package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.TransferAccountsPayStatusEnum;
import org.jsola.hr.dto.TransferAccountsBatchAddDTO;
import org.jsola.hr.dto.TransferAccountsBatchUpdateDTO;
import org.jsola.hr.entity.TransferAccountsBatchDO;
import org.jsola.hr.query.TransferAccountsBatchQuery;
import org.jsola.hr.service.ITransferAccountsBatchService;
import org.jsola.hr.vo.TransferAccountsBatchVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 转账批次
 *
 * @author zhr
 */
@Component
public class TransferAccountsBatchTestHelper extends BaseTestHelper {
    
    @Autowired
    private ITransferAccountsBatchService transferAccountsBatchService;

    /**
     * 生成add测试数据
     * @return TransferAccountsBatchAddDTO
     */
    public TransferAccountsBatchAddDTO getTransferAccountsBatchAddDTO(){
        TransferAccountsBatchAddDTO transferAccountsBatchAddDTO = new TransferAccountsBatchAddDTO();
        transferAccountsBatchAddDTO.setCreateUserName(getRandomValue("varchar",50));
        transferAccountsBatchAddDTO.setUserApproId(getRandomValue("varchar",32));
        transferAccountsBatchAddDTO.setCompanyId(getRandomValue("varchar",32));
        transferAccountsBatchAddDTO.setCompanyName(getRandomValue("varchar",50));
        transferAccountsBatchAddDTO.setSubjectId(getRandomValue("varchar",32));
        transferAccountsBatchAddDTO.setType(SafeKit.getInteger(getRandomValue("int",4)));
        transferAccountsBatchAddDTO.setSecondType(SafeKit.getInteger(getRandomValue("int",4)));
        transferAccountsBatchAddDTO.setThirdpartyBatchId(getRandomValue("varchar",100));
        transferAccountsBatchAddDTO.setThirdPartyInteriorBatchId(getRandomValue("varchar",200));
        transferAccountsBatchAddDTO.setOrderTitle(getRandomValue("varchar",64));
        transferAccountsBatchAddDTO.setMoney(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        transferAccountsBatchAddDTO.setTotalCount(SafeKit.getInteger(getRandomValue("int",10)));
        transferAccountsBatchAddDTO.setSuccessCount(SafeKit.getInteger(getRandomValue("int",10)));
        transferAccountsBatchAddDTO.setSuccessMoney(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        transferAccountsBatchAddDTO.setFailCount(SafeKit.getInteger(getRandomValue("int",10)));
        transferAccountsBatchAddDTO.setFailMoney(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        transferAccountsBatchAddDTO.setTimeExpire((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        transferAccountsBatchAddDTO.setRemark(getRandomValue("varchar",256));
        transferAccountsBatchAddDTO.setSubjectStatus(SafeKit.getInteger(getRandomValue("int",4)));
        transferAccountsBatchAddDTO.setPayStatus(TransferAccountsPayStatusEnum.NO_PAY.getValue());
        transferAccountsBatchAddDTO.setIssueUserId(getRandomValue("varchar",32));
        transferAccountsBatchAddDTO.setIssueUserName(getRandomValue("varchar",20));
        transferAccountsBatchAddDTO.setIssueCreate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        transferAccountsBatchAddDTO.setIssueAccountName(getRandomValue("varchar",100));
        transferAccountsBatchAddDTO.setPayType(SafeKit.getInteger(getRandomValue("int",4)));
        transferAccountsBatchAddDTO.setTransferCreate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        transferAccountsBatchAddDTO.setFailCause(getRandomValue("varchar",200));
        transferAccountsBatchAddDTO.setIsDispose(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return transferAccountsBatchAddDTO;
    }


    /**
     * 生成update测试数据
     * @return TransferAccountsBatchUpdateDTO
     */
    public TransferAccountsBatchUpdateDTO getTransferAccountsBatchUpdateDTO(TransferAccountsBatchVO transferAccountsBatchVO){
        return transferAccountsBatchService.selectDOById(transferAccountsBatchVO.getId(), SITE_ID).to(TransferAccountsBatchUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return TransferAccountsBatchQuery
     */
    public TransferAccountsBatchQuery getTransferAccountsBatchQuery() {
        TransferAccountsBatchQuery transferAccountsBatchQuery = new TransferAccountsBatchQuery();
        List<TransferAccountsBatchDO> transferAccountsBatchDOList = transferAccountsBatchService.list(new TransferAccountsBatchDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(transferAccountsBatchDOList)) {
            TransferAccountsBatchDO transferAccountsBatchDO = transferAccountsBatchDOList.get(0);
            transferAccountsBatchQuery = transferAccountsBatchDO.to(TransferAccountsBatchQuery.class);
            if (transferAccountsBatchDO.getGmtCreate() != null) {
                transferAccountsBatchQuery.setGmtCreateStart(DateKit.getBeforeDay(transferAccountsBatchDO.getGmtCreate(),-1));
                transferAccountsBatchQuery.setGmtCreateEnd(DateKit.getBeforeDay(transferAccountsBatchDO.getGmtCreate(),1));
            }
        }
        return transferAccountsBatchQuery;
    }

    /**
     * 保存示例
     * @return TransferAccountsBatchVO
     */
    public TransferAccountsBatchVO saveTransferAccountsBatchExample(){
        TransferAccountsBatchAddDTO addDTO = this.getTransferAccountsBatchAddDTO();
        TransferAccountsBatchVO transferAccountsBatchVO = transferAccountsBatchService.save(addDTO,buildTokenUser());
        return transferAccountsBatchVO;
    }


}

